﻿ 
using NBHF.Common;
using NBHF.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NBHF.BusinessService
{
    public sealed class UserService
    {
        /// <summary>
        /// APP用户登陆
        /// </summary> 
        public static AppUserLoginResultModel AppUserLogin(
            string phone,
            string pwd)
        {
            AppUserLoginModel obj = new AppUserLoginModel();
            obj.phone = phone;
            obj.passwd = pwd;

            string ip = ConfigurationManager.AppSettings["url"];

            string url = $"{ip}/WisdomWebAPI/AppUser/AppUserLogin";

            string json = JsonConvert.SerializeObject(obj);


            try
            {
                json = HttpHelper.HttpPost(url, json);

                AppUserLoginResultModel resultobj = (AppUserLoginResultModel)JsonConvert.DeserializeObject<AppUserLoginResultModel>(json);
                if (resultobj.code != "0")
                    throw new Exception(resultobj.message);

                return resultobj;
            }
            catch (Exception ex)
            {
                AppUserLoginResultModel resultobj = new AppUserLoginResultModel();
                resultobj.code = "99";
                resultobj.message = ex.Message;
                return resultobj;
            }
        }
    }
}
